package org.example.lethear.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 分类实体类
 */
@Entity
@Table(name = "categories")
@Data
@EqualsAndHashCode(callSuper = false)
@EntityListeners(AuditingEntityListener.class)
public class Category {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(nullable = false, length = 50)
    private String name;
    
    @Column(length = 200)
    private String description;
    
    @Column(name = "parent_id", columnDefinition = "BIGINT DEFAULT 0")
    private Long parentId;
    
    @Column(name = "sort_order", columnDefinition = "INT DEFAULT 0")
    private Integer sortOrder;
    
    @Column(columnDefinition = "TINYINT DEFAULT 1")
    private Integer status; // 0-禁用，1-正常
    
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;
    
    // 构造方法
    public Category() {}
    
    public Category(String name, String description) {
        this.name = name;
        this.description = description;
        this.parentId = 0L;
        this.sortOrder = 0;
        this.status = 1;
    }
    
    public boolean isEnabled() {
        return status != null && status == 1;
    }
} 